{extend name="base"}
{block name="body"}
<ol class="breadcrumb">
  <li><a href="#">首页</a></li>
  <li class="active">友情链接管理</li>
</ol>
<a href="{:url('linksAdd')}" class="btn btn-default">
  添加链接
</a>

<table class="table table-bordered">
  <tr>
    <th style="width: 30px">ID</th>
    <th style="width: 100px">链接名称</th>
    <th style="width: 300px">链接地址</th>
    <th style="width: 30px">排序</th>
    <th style="width: 80px">新窗口打开</th>
    <th style="width: 80px">是否显示</th>
    <th style="width: 200px">操作</th>
  </tr>
  {foreach $linksList as $linkVal}
  <tr>
    <td>
      {$linkVal.id}
    </td>
    <td>
      <input type="text" class="form-control" value="{$linkVal.link_name}">
    </td>
    <td>
      <input type="text" class="form-control" value="{$linkVal.link_url}">
    </td>
    <td>
      <input type="text" class="form-control" value="{$linkVal.orderby}">
    </td>
    <td>
      {switch name="$linkVal.target" }
        {case value="1"}
          <span class="glyphicon glyphicon-ok-circle"></span>是
        {/case}
        {case value="0"}
          <span class="glyphicon glyphicon-remove-circle"></span>否
        {/case}
      {/switch}      
    </td>
    <td>
      {switch name="$linkVal.is_show" }
        {case value="1"}
          <span class="glyphicon glyphicon-ok-circle"></span>是
        {/case}
        {case value="0"}
          <span class="glyphicon glyphicon-remove-circle"></span>否
        {/case}
      {/switch}  
    </td>
    <td>
      <a href="{:url('linksEdit','id='.$linkVal.id)}" class="btn btn-default">编辑</a>
      <a href="javascript:" class="btn btn-default link-del" data-id="{$linkVal.id}">删除</button>
    </td>
  </tr>
  {/foreach}
</table>
<script>
$('.link-del').on('click',function(){
  var id=$(this).attr('data-id');
  var obj=$(this);
  $.ajax({
    url: '{:url("linksDel")}',
    type: 'GET',
    dataType: 'json',
    data: {'id':id},
  })
  .done(function(r) {
    if(r){
      obj.parents("tr").hide(300);
    }
  })
  .fail(function() {
    console.log("error");
  })  
});
</script>
{/block}